package com.newbee.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hhu.newbee.R;
import com.newbee.listbean.InviteMultBean;
import com.newbee.sqlite.DBHelper;

public class InviteMultCharAdapter extends BaseAdapter
{

	private List<InviteMultBean> list;

	private Context context;

	public void setList(List<InviteMultBean> list)
	{
		this.list = list;
	}

	public InviteMultCharAdapter(List<InviteMultBean> list, Context context)
	{
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		if (list != null)
		{
			return list.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int arg0)
	{
		return arg0;
	}

	@Override
	public long getItemId(int arg0)
	{
		return arg0;
	}

	@Override
	public View getView(int p, View v, ViewGroup arg2)
	{

		if (v == null)
		{
			v = LayoutInflater.from(context).inflate(
					R.layout.listitem_ask_mult_chat, null);
		}

		ViewHolder holder = new ViewHolder();

		holder.content = (TextView) v.findViewById(R.id.invite_list_content);
		holder.img = (ImageView) v.findViewById(R.id.invite_list_img);

		holder.solve = (TextView) v.findViewById(R.id.invite_list_state);
		holder.time = (TextView) v.findViewById(R.id.invite_list_time);

		InviteMultBean bean = list.get(p);

		holder.content.setText("有来自 " + bean.getRoomName().split("\\$")[1]
				+ "的协同录音请求");
		holder.time.setText(bean.getTime());
		holder.solve.setText(bean.getStatue() == DBHelper.SOLVE ? "[已处理]"
				: "[未处理]");

		if (bean.getStatue() == DBHelper.SOLVE)
		{
			holder.img.setImageDrawable(context.getResources().getDrawable(
					R.drawable.caution_solve));

		}
		else
		{
			holder.img.setImageDrawable(context.getResources().getDrawable(
					R.drawable.caution_unsolve));
		}
		return v;

	}

	static class ViewHolder
	{

		TextView content;
		TextView solve;
		TextView time;
		ImageView img;
	}

}
